package com.saibo.spider.commons;

import java.util.HashMap;
import java.util.Map;

import org.apache.http.client.methods.CloseableHttpResponse;

import com.saibo.spider.utils.HttpRequestUtil;
import com.saibo.spider.utils.HttpResponseUtil;
import com.saibo.spider.utils.StringUtil;


public class SubmitRedisCommons {
	
	public static String REDISSUBMITSERVERURL = "http://123.57.255.38:8080/kolselfmedia_manager/api/submit2redis.do";
	public static String REDISGETSERVERURL = "http://123.57.255.38:8080/kolselfmedia_manager/api/getdata.do";
	
	public static void submitRedisData(final String redisKey, final String json) {
		new Thread(new Runnable() {
			public void run() {
				Map<String, String> mso = new HashMap<String, String>();
				mso.put("redisKey", redisKey);
				mso.put("redisValue", json);
				CloseableHttpResponse httpResponse = HttpRequestUtil
						.postRequestMethod(REDISSUBMITSERVERURL, null, mso);
				String stat = HttpResponseUtil.getHtml(httpResponse);
				System.out.println(stat);
			}
		}).start();
	}
	
	/***
	 * 获取Redis某一个队列的内容
	 * 
	 * @param redisKey
	 * @return
	 */
	public static String getRedisData(String redisKey) {
		if (StringUtil.isNullOrEmpty(redisKey)) {
			return "parameter can not be null!!!";
		}
		CloseableHttpResponse httpResponse = HttpRequestUtil
					.getRequestMethod(REDISGETSERVERURL+"?redisKey=" + redisKey, null);
		return HttpResponseUtil.getHtml(httpResponse);
	}
	
}
